﻿@page
@model DotNetStar.TheKing.Web.Pages.Account.FindPwdModel
    @{ 
        ViewBag.Title = "找回密码";
    }

<div class="row">
    <div class="col-5  mx-auto border pt-3">
        <h3>@ViewBag.Title</h3>
        <div class="form-group mt-4">
            <input class="form-control form-control-lg" placeholder="手机号码" id="Account" />
        </div>
        <div class="form-group mt-4">
            <div class="row">
                <div class="col-6">
                    <input class="form-control form-control-lg" placeholder="验证码" type="text" id="Code" />
                </div>
                <div class="col-6">

                    <button class="btn btn-primary btn-block btn-lg" onclick="sendCode(this,$('#Account'))" formnovalidate type="button">
                        发送验证码
                    </button>
                </div>
            </div>
        </div>
        <div class="form-group mt-4">
            <input class="form-control form-control-lg" placeholder="设置密码，8-25个字符" type="password" id="Password" />
        </div>
        <div class="form-group mt-4">
            <input class="form-control form-control-lg" placeholder="再次输入密码" type="password" id="ConfirmPassword" />
        </div>
        <div class="form-group mt-4">
            <button class="btn btn-dark btn-block btn-lg" onclick="return submit()">提 交</button>
        </div>
        <div class="mt-3 mb-3">
            <div class="float-left">
                <a asp-page="Login">立即登录</a>
            </div>
            <div class="float-right">
                <a asp-page="Register">快速注册</a>
            </div>
        </div>
    </div>
</div>
@section scripts{
    @Html.Partial("../Shared/_ValidationScripts.cshtml")

<script type="text/javascript">
    $('footer').addClass('fixed-bottom');
        function submit() {
            var account = $('#Account').val();
            var code = $('#Code').val();
            var password = $('#Password').val();

            if (!account) {
                bootbox.alert('请输入帐号');
                return false
            }

            if (!code) {
                bootbox.alert('请输入验证码');
                return false
            }
            if (!password) {
                bootbox.alert('请输入密码');
                return false
            }
            if (password != $('#ConfirmPassword').val()) {
                bootbox.alert('两次密码输入不一致');
                return false
            }
            var index= layer.load(2);
            $.ajax({
                beforeSend: function (xhr) {
                    xhr.setRequestHeader("XSRF-TOKEN",
                        $('input:hidden[name="__RequestVerificationToken"]').val());
                },
                data: {
                    account: account,
                    code: code,
                    password: password
                },
                url: '@Url.Page("FindPwd")',
                type: 'post',
                success: function (data) {
                    bootbox.confirm({
                        title: '重置密码',
                        message: '密码已经重置成功',
                        buttons: {
                            confirm: {
                                className: 'btn btn-success',
                                label: '<i class="fa fa-sign-in-alt"></i> 现在去登录'
                            },
                            cancel: {
                                className: 'btn btn-default',
                                label:'<i class="fa fa-home"></i> 返回首页'
                            }
                        },
                        closeButton: false,
                        callback: function (result) {
                            if (result) {
                                location.href = '@Url.Page("./Login")';
                            } else {
                                location.href = '/';
                            }
                        }
                    });
                },
                error: function (data) {
                    bootbox.alert(data.responseText);
                },
                complete: function () {
                    layer.close(index);
                }
            });
        }
</script>
}